import Vue from 'vue'
import VueRouter from 'vue-router'
import Store from "../store/index"
import { getToken } from '@/utils/auth.js'
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function(location) {
  return originalPush.call(this, location).catch(err => err)
}
Vue.use(VueRouter)
const routes = [
  /* {
    path: '/',
    name: 'home',
    meta:{
      title:"员工打卡预览"
    },
    component: HomeView
  }, */
  {
    path: '/',
    name: 'login',
    meta:{
      title:"登陆页"
    },
    component: () => import( '../views/Login.vue')
  },
  /* {
    path:"/person",
    name:"Person",
    meta:{
      title:"人员管理"
    },
    component:() => import("../views/Person")
  } */
  ,{
    path:"/healthy",
    name:"Healthy",
    meta:{
      title:"健康打卡管理"
    },
    component:()=>import("../views/Healthy.vue")
  },
  /* {
    path:"/manger",
    name:"Manger",
    meta:{
      title:"权限管理"
    },
    component:()=>import("../views/Manger.vue")
  },{
    path:"/log",
    name:"Log",
    meta:{
      title:"登陆日志"
    },
    component:()=>import("../views/Log.vue")
  },{
    path:"/three",
    name:"three",
    meta:{
      title:"三级"
    },
    component:()=>import("../views/three.vue")
  },{
    path:"/try",
    name:"try",
    meta:{
      title:"三级"
    },
    component:()=>import("../views/try.vue")
  }, */
  
]

const router = new VueRouter({
  mode: 'hash',
  base: process.env.BASE_URL,
  routes
})
router.beforeEach((to,from,next)=>{
  document.title = to.meta.title;
  const token = getToken();
  if(to.path!="/"&&!token){
      next({
        path:'/'
      })
  }
  else{
    next()
  }
})


export default router
